#ifndef _DEVICE_CTRL_H_
#define _DEVICE_CTRL_H_

#include "spk_packet.h"

class cls_device_ctrl : public spk_packet
{

public:
    cls_device_ctrl(/* args */);
    ~cls_device_ctrl();

    /*开始运行*/
    int run(string server_ip = "", int port = DEVICE_CTRL_PORT);

    int get_device_info(struct device_info *msg); // 这里的config路径已经写死了
    int set_device_info(struct device_info *msg);

    /*设备端方法*/

    /*重启设备*/
    int reboot(void);
    /*刷新设备*/
    int refresh(void);
    /*控制设备*/
    int ctrl(void *data);

    /*设备信息通知窗口句柄*/
    HWND notify_win;

    int on_refresh_ack(void *data, int len);
    int on_ctrl_ack(void *data, int len);
    int on_reboot_ack(void *data, int len);

private:
    int fd;
    int fd_c;

    std::thread *thread;
    static void recv_packet_thread(void *arg);

    virtual int io_write(void *data, int len, void *param = NULL);
    static void on_rx_packet(void *rx_buffer, int len, u8 type, void *param);
    static int io_read(void *data, int len, int time_out_ms, void *param);
};

#endif //  _DEVICE_CTRL_H_
